#include <math.h>

int LEDlight = 100;
int num = 5;

void setup() {
  // put your setup code here, to run once:
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(A0, INPUT);
  Serial.begin(9600);

}

short int T0 = 10;
short int a0 = 815;
short int T1 = 60;
short int a1 = 397;
short int a = analogRead(A0);
short int T = convert_adc2temperature(a,a0, a1,T0, T1);
  
 short int LT = T;
void loop() {
  // put your main code here, to run repeatedly:
  a = analogRead(A0);
  T = convert_adc2temperature(a,a0, a1,T0, T1);
  
  analogWrite(12, LEDlight);
  analogWrite(11, LEDlight);
  if(LT < T)
    num = -5;
   else if(LT > T)
     num = 5;
   else
     num = 0;
   LEDlight = LEDlight + num;
    LT = T;
  delay(50);
  
}


short int convert_adc2temperature(short int ax,short int a0,short int a1,short int temp0, short int temp1)
{ 
  short int tempx;
  tempx = temp0+(ax-a0)*(temp1-temp0)/(a1-a0);
  return tempx - 20;
}
